<?php

/*
 * Copyright 2008 Jeffrey Palm
 */


include '../config.php';
include '../../common.php';
include '../../class.CronJob.php';
include 'fileupload/fileupload.class.php';

$upload = new fileupload();
$upload->set_max_filesize(5 * 1000000);
$upload->set_overwrite_mode(2);
$dir = 'uploads/';
$filename = $upload->upload("file", $dir);
$description = $_REQUEST['description'];
$location = $_REQUEST['location'];
$lat = $_REQUEST['lat'];
$lng = $_REQUEST['lng'];
if ($filename) {
  $file = $dir.$filename;
  $sec = datetime();
  $c = new CronJob();
  $c->processImageFile($file,$sec,$description,$location,$lat,$lng);
  
  $resolved = true;
 }

if ($resolved) {

  $code = 'ok';
  echo '<?xml version="1.0" encoding="utf-8" ?>';
  echo '<rsp stat="' . $code . '">';
  
  echo '<description>' . $description . '</description>';
  echo '<location>' . $location . '</location>';
  echo '<file>' . $newFile . '</file>';

  echo '</rsp>';

 } else {


  ?>
  
  <html>
  <body>

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
    <p>
    <table border=0 cellpadding= cellspacing=0>
    <tr><td>File: </td><td><input name="file" id="file" type="file"></td><tr>
    <tr><td>Description: </td><td><input type="text" size="50" name="description"></td></tr>
    <tr><td>Location: </td><td><input type="text" size="50" name="location"></td></tr>
    <tr><td>Latitude: </td><td><input type="text" size="50" name="lat"></td></tr>
    <tr><td>Longitude: </td><td><input type="text" size="50" name="lng"></td></tr>
    <tr><td><input class=tbox type=submit value="Upload file"></td></tr>
    </table>
<?php
          if ($error) {
            echo '<p style="color:red">';
            echo $error;
            echo '</p>';            
          } else if ($resolved) {
            echo '<p style="color:green">';
            echo $file . ' uploaded';
            echo '</p>';
          }
  ?>
</p>
            </form>

  </body>
  </html>

  <?php
 }

?>

